package gom.example.gramediamajalah;

import java.security.PublicKey;
import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Editable;
import android.text.StaticLayout;
import android.text.TextWatcher;
import android.webkit.JsPromptResult;
import android.widget.EditText;
import android.widget.ListView;

public class MainSearch extends Activity {
	ListView list;
	ListAdapter adapter;

	ArrayList<HashMap<String, String>> contactList;

	EditText inputSearch;
	int textLength = 0;

	String url = " ";

	// json node names
	static final String TAG_TITLE = "title";

	public void onCreate(Bundle savedINstanceState) {
		super.onCreate(savedINstanceState);
		setContentView(R.layout.list_item);
		inputSearch = (EditText) findViewById(R.id.action_settings);

		contactList = new ArrayList<HashMap<String, String>>();

		inputSearch.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
				// TODO Auto-generated method stub

			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
				// TODO Auto-generated method stub

			}

			@Override
			public void afterTextChanged(Editable s) {
				// TODO Auto-generated method stub

			}
		});
	}

	class Search extends AsyncTask<String, String, String> {

		protected void onPreExcecitue() {
			super.onPreExecute();
			ProgressDialog pDialog = new ProgressDialog(MainSearch.this);
			pDialog.setIndeterminate(false);
			pDialog.setCancelable(false);
			pDialog.show();

		}

		@Override
		protected String doInBackground(String... params) {

			JSONParser jParser = new JSONParser();
			JSONObject json = jParser.getJSONFromUrl("");

			try {
				JSONArray userinfo;
				userinfo = json.getJSONArray(TAG_TITLE);
				for (int i = 0; i < userinfo.length(); i++) {
					JSONObject c = userinfo.getJSONObject(i);
					HashMap<String, String> map = new HashMap<String, String>();
					String title = null;
					map.put(TAG_TITLE, title);
					contactList.add(map);
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}

			return null;

		}

		@Override
		protected void onPostExecute(String file_url) {

			runOnUiThread(new Runnable() {
				public void run() {

					list = (ListView) findViewById(R.id.action_settings);

					// Getting adapter by passing xml data ArrayList
					list.setAdapter(adapter);
				}
			});

		}
	}
}
